/**
 * 
 */
package pms.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import pms.om.Musikstueck;
import pms.om.Stimme;

/** 
 * Controller to generate the Home Page basics to be rendered by a view. 
 * It extends the convenience class AbstractController that encapsulates most 
 * of the drudgery involved in handling HTTP requests. 
/**
 * @author roman.zaglauer@googlemail.com
 *
 */
public class SaveNoten extends AlleNoten {
	protected ModelAndView handleRequestInternal(
			HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws Exception {
		httpServletRequest.setCharacterEncoding("UTF-8");
		
//		int id = Integer.parseInt(httpServletRequest.getParameter("id"));
		int id = 0; // TODO: temp solution
		int musikstueckid = Integer.parseInt(httpServletRequest.getParameter("musikstueckid"));
		Musikstueck musikstueck = getNotenDao().getMusikstueckDao().findById(musikstueckid);
		
		int stimmeid = Integer.parseInt(httpServletRequest.getParameter("stimme"));
		Stimme stimme = getNotenDao().getStimmeDao().findById(stimmeid);
		
		if (id == 0) {
			getNotenDao().create(null, stimme, musikstueck);
		} else {
			getNotenDao().modify(id, null, stimme, musikstueck);
		}
		
		return super.handleRequestInternal(httpServletRequest, httpServletResponse);
	}
}
